import axios from "axios";

axios.defaults.baseURL = "http://www.kangliuyong.com:10002/";

let appkey = "U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=";

// 添加请求拦截器
axios.interceptors.request.use(
  function (config) {
    // 在发送请求之前做些什么

    config.params = config.params || {};
    config.params.appkey = appkey;

    if(config.method === 'post'){
      let dataParams = '';
      for(let key in config.data){
        dataParams += `${key}=${config.data[key]}&`
      }
      config.data = dataParams.slice(0,-1)
    }
    

    return config;
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

export default axios;
